package com.honghu.cloud.utils;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;
import com.honghu.cloud.bean.Goods;
import com.honghu.cloud.bean.Transport;
import com.honghu.cloud.dto.AreaDto;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.service.ITransportService;
import com.honghu.cloud.utils.domain.SysMap;

/**
 * 运费模板工具类，用来处理运费模板相关信息
 * @author Administrator
 *
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Component
public class TransportTools {
	@Autowired
	private ITransportService transportService;

	public List<SysMap> query_pin_goods_trans(Goods goods,BigDecimal price, String area_id) {
		List<SysMap> sms = Lists.newArrayList();
		
			//AreaDto current_area = areaFeignClient.selectByPrimaryKey(CommUtil.null2Long(area_id));
			//AreaDto area = areaFeignClient.selectByPrimaryKey(CommUtil.null2Long(current_area.getParent_id()));
			//String city_name = area.getAreaName();
			
			float mail_fee = 0.0F;
			float express_fee = 0.0F;
			float ems_fee = 0.0F;
			String fee_tip = "商家承担";

			Transport transport = null;
			BigDecimal weight = new BigDecimal(0);
			BigDecimal volume = new BigDecimal(0);
			
			if (goods.getGoods_transfee() == 0) {
					mail_fee = mail_fee
							+ CommUtil.null2Float(goods
									.getMail_trans_fee());
					
					express_fee = express_fee
							+ CommUtil.null2Float(goods
									.getExpress_trans_fee());
					
					ems_fee = ems_fee
							+ CommUtil.null2Float(goods
									.getEms_trans_fee());
			}
		
			if ((mail_fee == 0.0F) && (express_fee == 0.0F) && (ems_fee == 0.0F)) {
				sms.add(new SysMap(fee_tip, Integer.valueOf(0)));
			} else  {
				Transport cart_goods_transport=transportService.selectByPrimaryKey(goods.getTransport_id());
				if (null != cart_goods_transport && null !=cart_goods_transport.getId()) {
					
					if (cart_goods_transport.getTrans_mail()) {
						sms.add(new SysMap("平邮[" + mail_fee + "元]", Float.valueOf(mail_fee)));
					}
					if (cart_goods_transport.getTrans_express()) {
						sms.add(new SysMap("快递[" + express_fee + "元]",Float.valueOf(express_fee)));
					}
					if (cart_goods_transport.getTrans_ems()) {
						sms.add(new SysMap("EMS[" + ems_fee + "元]", Float.valueOf(ems_fee)));
					}
				} else {
					if (mail_fee > 0.0F) {
						sms.add(new SysMap("平邮[" + mail_fee + "元]", Float.valueOf(mail_fee)));
					}
					if (express_fee > 0.0F) {
						sms.add(new SysMap("快递[" + express_fee + "元]", Float.valueOf(express_fee)));
					}
					if (ems_fee > 0.0F) {
						sms.add(new SysMap("EMS[" + ems_fee + "元]", Float.valueOf(ems_fee)));
					}
				}
			} 
		return sms;
	}
	
	
	
}
